package com.example.baiduai.utils;



import java.util.Map;

public class JsonResult<T> {
    private Integer code;
    private String msg;
    private T data;

    public JsonResult() {
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    @Override
    public String toString() {
        return "code=" + code + " message=" + msg + " data=" + data;
    }

    public static <T> JsonResult<T> fail() {
        JsonResult<T> ret = new JsonResult<T>();
        ret.setCode(500);
        ret.setMsg("操作失败");
        return ret;
    }

    public static <T> JsonResult<T> fail(T data) {
        JsonResult<T> ret = new JsonResult<T>();
        ret.setCode(500);
        ret.setMsg(String.valueOf(data));
        return ret;
    }







    public static <T> JsonResult<T> fail(Integer code, String msg) {
        JsonResult<T> ret = new JsonResult<T>();
        ret.setCode(code);
        ret.setMsg(msg);
        return ret;
    }





    public static JsonResult success() {
        JsonResult ret = new JsonResult();
        ret.setCode(200);
        ret.setMsg("success");
        return ret;
    }


    public static <T> JsonResult<T> success(T data) {
        JsonResult<T> ret = JsonResult.success();
        ret.setMsg("success");
        ret.setData(data);
        return ret;
    }

    public static <T> JsonResult<T> successMessage(String message) {
        JsonResult ret = new JsonResult();
        ret.setCode(200);
        ret.setMsg(message);
        return ret;
    }





}
